package net.zjitc.servlet;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/9/21.
 */
public class BServlet implements Servlet {
    //第一步：定义一个成员变量servletConfig，所以方法都可以使用
    private ServletConfig servletConfig = null;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        //第二步：初始化时赋值servletConfig
        this.servletConfig = servletConfig;
        System.out.println("birth");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //查询了a，在查询b，b的后面可以接a
        PrintWriter out = servletResponse.getWriter();
        out.write("bServlet......");
        ServletContext context = this.servletConfig.getServletContext();
        String value = (String) context.getAttribute("name");
        out.write(value);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
